<?php
namespace Sys\Controller;
use Todo\Controller\ApiController;
use Todo\Service\UserService;

class UserController extends ApiController {

    protected $_field = 'id,account,nickname,last_time,last_ip,status,mobile,email,depart_id';
    protected $_format = 'depart';

    protected function _filter(&$where){
        $where['is_del'] = 0;
        $keyword = I('get.keyword/s');
        if($keyword) $where['_string'] = "account like '%" . $keyword . "%' OR nickname like '%" . $keyword . "%'";
    }

    /**
     * 用户修改密码
     */
    public function password(){
        $id = I('post.id');
        if(!$id) $this->apiError('非法请求');

        $oldp = I('post.oldp');
        $password = I('post.password');

        $ret = UserService::getInstance()->changePassword($id , $oldp, $password);
        if($ret === false){
            $this->apiError('发生错误!'.UserService::getInstance()->getError());
        }else{
            $this->apiSuccess(null,'修改成功!');
        }
    }
}